package com.zhc.dejingapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhc.dejingapi.entity.QingProcessplanEntity;
import com.zhc.dejingapi.mapper.QingMoldMapper;
import com.zhc.dejingapi.mapper.QingProcessplanMapper;
import com.zhc.dejingapi.service.QingProcessplanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhc
 * @since 2024-10-08
 */
@Service
public class QingProcessplanServiceImpl extends ServiceImpl<QingProcessplanMapper, QingProcessplanEntity> implements QingProcessplanService {

    @Resource
    private QingProcessplanMapper qingProcessplanMapper;

    @Resource
    private QingMoldMapper qingMoldMapper;
    @Override
    public List<QingProcessplanEntity> getInjectionList(String eqCode) {
        List<QingProcessplanEntity> qingProcessplanEntities=null;
        List<String> invList = qingMoldMapper.getInvList(eqCode+"#");
        if(!invList.isEmpty()){
            QueryWrapper<QingProcessplanEntity> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("process_name","注塑");
            queryWrapper.in("inv_code",invList);
            queryWrapper.last("AND (ISNULL(total_send_work_num) or total_send_work_num < transfer_to_num)");
            qingProcessplanEntities= qingProcessplanMapper.selectList(queryWrapper);
        }
        return qingProcessplanEntities;

    }

    @Override
    public QingProcessplanEntity addProcessPlan(QingProcessplanEntity qingProcessplanEntity) {
        int insert = qingProcessplanMapper.insert(qingProcessplanEntity);
        if(insert>0){
            return qingProcessplanEntity;
        }else {
            return null;
        }
    }



    @Override
    public List<QingProcessplanEntity> getJobList(Long eId) {
        QueryWrapper<QingProcessplanEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("eq_code",eId+"#").eq("process_plan_sts","在生产").eq("process_name","注塑");
        return qingProcessplanMapper.selectList(queryWrapper);
    }

    @Override
    public QingProcessplanEntity getInfoById(Long mainId) {
        return qingProcessplanMapper.getInfoById(mainId);
    }

    @Override
    public QingProcessplanEntity selectBoilingProcessPlan(String boilingBoxCode) {
        QueryWrapper<QingProcessplanEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("boiling_box_code",boilingBoxCode);
        QingProcessplanEntity qingProcessplanEntity = qingProcessplanMapper.selectOne(queryWrapper);

        return qingProcessplanEntity;
    }

    @Override
    public List<QingProcessplanEntity> getWithdrawalOfPipeList() {
        QueryWrapper<QingProcessplanEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("process_plan_sts","在生产").eq("process_name","退管子");
        return qingProcessplanMapper.selectList(queryWrapper);
    }
}
